using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AutoGear.BLL;
using ECommerce.Library.Mail;
using System.Collections.Specialized;



public partial class recover : SitePublicBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ContentPlaceHolder ph = (ContentPlaceHolder)this.Master.Master.FindControl("cphMiddleContent");

            Literal litPageTitle = (Literal)ph.FindControl("litPageTitle");
            Literal litCurrentPage = (Literal)ph.FindControl("litCurrentPage");

            if (litPageTitle != null)
            {
                litCurrentPage.Text = litPageTitle.Text = "Recover";

            }
        }
    }

    protected void btnRecoverMyPassword_Click(object sender, EventArgs e)
    {
        try
        {
            //this.Page.Validate();

            if (IsValid)
            {
                string LoginEmailAddress = tbxEmailAddress.Text.Trim();
                if (AutoGearSiteUser.IsUserExists(LoginEmailAddress))
                {

                    CustomerUser customerUser = CustomerUser.GetCustomerUserByUserName(LoginEmailAddress);
                    if (customerUser != null)
                    {
                        if (Email.SendPasswordRecoverEmail(customerUser))
                        {
                            uccResponseMessage.SetSuccessMessage("An email with your password has been sent to" + customerUser.Profile.EmailAddress + ". <a href="+ CustomSiteMap.Login+"> click here to login</a>");
                            uccResponseMessage.Visible = true;
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                else
                {
                    uccResponseMessage.SetFailMessage("Member not found with this email address.");
                    uccResponseMessage.Visible = true;
                }
            }
        }
        catch (Exception ex)
        {
            uccResponseMessage.SetFailMessage("Password recovery failed. Please try later.");
            uccResponseMessage.Visible = true;
        }
    }
}
